package com.gmail.dmitryustimov.ms.java7.observer.classic.demo.subj1subsc10event10;

import java.math.BigDecimal;

public class Subscriber implements Observer {

    private String name;
    private Subject subject;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public Subscriber(Subject subject, String name) {
        this.name = name;
        this.subject = subject;
        subject.registerObserver(this);
    }

    @Override
    public void update(Event event) {
        if (event instanceof Event1) {
            process((Event1)event);
        }
        if (event instanceof Event2) {
            process((Event2)event);
        }
        if (event instanceof Event3) {
            process((Event3)event);
        }
        if (event instanceof Event4) {
            process((Event4)event);
        }
        if (event instanceof Event5) {
            process((Event5)event);
        }
        if (event instanceof Event6) {
            process((Event6)event);
        }
        if (event instanceof Event7) {
            process((Event7)event);
        }
        if (event instanceof Event8) {
            process((Event8)event);
        }
        if (event instanceof Event9) {
            process((Event9)event);
        }
        if (event instanceof Event10) {
            process((Event10)event);
        }
    }

    private void process(Event1 event) {
        sum.add(BigDecimal.valueOf(1));
    }

    private void process(Event2 event) {
        sum.add(BigDecimal.valueOf(2));
    }

    private void process(Event3 event) {
        sum.add(BigDecimal.valueOf(3));
    }

    private void process(Event4 event) {
        sum.add(BigDecimal.valueOf(4));
    }

    private void process(Event5 event) {
        sum.add(BigDecimal.valueOf(5));
    }

    private void process(Event6 event) {
        sum.add(BigDecimal.valueOf(6));
    }

    private void process(Event7 event) {
        sum.add(BigDecimal.valueOf(7));
    }

    private void process(Event8 event) {
        sum.add(BigDecimal.valueOf(8));
    }

    private void process(Event9 event) {
        sum.add(BigDecimal.valueOf(9));
    }

    private void process(Event10 event) {
        sum.add(BigDecimal.valueOf(10));
    }
}
